//公用样式 
require('../../assets/css/index.less')

require('../../assets/fonts-wei/iconfont.css')
require('../../assets/fonts/iconfont.css');
require('../../assets/lib/swiper/swiper.css')

let Swiper = require('../../assets/lib/swiper/swiper')
//工具函数 utils
const dom = require('../../utils/dom');

const local = require('../../utils/local.js');
//引入axios封装的文件
let https = require('../../utils/https.js');

// // 当前页面样式
require('./my.less')


// 当前js

dom.isLogin()
dom.ready(function () {

    //调用底部菜单
    dom.bMenu('my');
    // 轮播图
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

    })

    // 获取用户个人信息
    function getUserInfo() {
        https.get('/api/user/info', function (res) {
            //参数解构出来
            let {
                errno,
                data
            } = res;
            //  渲染数据到网页
            console.log(data);

            dom.getEle('#headPicVal').src = https.BASE_URL + data.imgUrl;
            dom.getEle('#nicknameVal').innerHTML = data.nickName;
            dom.getEle('#signVal').innerHTML = data.sign;
            dom.getEle('#dynamicCount').innerHTML = data.circlesCount;
               //保存个人数据到本地
               local.set('userInfo', data)

        })
    }
    getUserInfo()

    // 获取累计打卡

    //获取打卡信息
    function getClockIn() {
        https.get('/api/user/clockInInfo', function (res) {
            //参数解构出来
            let {
                errno,
                data
            } = res;
            if (errno == 0) {
                console.log(data);
                //渲染数据
                dom.getEle('#clockCountVal').innerHTML = data.clockCount;
                //文字
                dom.getEle('#clockBtn').innerHTML = data.isClockIn ? '已经打卡' : '今日打卡';

            }

        })
    }

    getClockIn()


    //  获取运动数据
    function sportData() {
        https.get('/api/exercise', function (res) {
            let {
                errno,
                data
            } = res;
            console.log(data);
            dom.getEle('#sportMinutes').innerHTML = data.days[0].sumDuration;
            dom.getEle('#kilocalorie').innerHTML = data.days[0].sumCalorie;
        })
    }

    sportData()
    
    //    退出登录
    dom.addEvent('#exit-longin',function(){
        localStorage.removeItem('token');
        // localStorage.removeItem('userInfo');
        
        location.href = './login.html';
    })


})